package com.lynx.system.controller;

import com.lynx.system.beans.Order;
import com.lynx.system.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    @PostMapping("/save")
    public void save(@RequestBody Order order){
        orderService.save(order);
    }
    @GetMapping("/findOrdersByUid/{uid}/{index}/{limit}")
    public List<Order> findOrdersByUid(@PathVariable long uid,@PathVariable int index,@PathVariable int limit){
        List<Order> orders = orderService.findOrdersByUid(uid,index,limit);
        return orders;
    }
    @GetMapping("/findCountByUid/{uid}")
    public int findCountByUid(@PathVariable long uid){
        int count = orderService.findCountByUid(uid);
        return count;
    }
    @GetMapping("/findOrdersByState/{state}/{index}/{limit}")
    public List<Order> findOrdersByState(@PathVariable int state,
                                         @PathVariable int index,
                                         @PathVariable int limit){
        List<Order> orders = orderService.findOrdersByState(state,index,limit);
        return orders;
    }
    @PutMapping("/editState/{id}")
    public void editState(@PathVariable long id){
        orderService.editState(id);
    }

    @GetMapping("/findCountByState/{state}")
    public int findCountByState(@PathVariable int state){
        int count = orderService.findCountByState(state);
        return count;
    }



}
